Music Object Extension - Instruments
|
|
This extension is designed to assist in the creation of music mixing interfaces (as well as other Web-based music applications) where users may be given the option of selecting different instruments to be played for different aspects of a musical arrangement. The extension makes it possible for an application's interface to offer meaningful instrument names, rather than just program numbers, making the application more user-friendly.
|
What's New in the Latest Version
|
There is a dedicated version history for this extension, where you will be able to find out about the new features and possible issues with the most recent version. The version history for this extension is independent of the version history for the core Music Object API.
To get the "music-object-x-instruments.js" JavaScript file that implements this extension, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object-x-instruments.js" into an appropriate folder of the local copy of your Web site.
In case you have problems saving the file using the above link, the "music-object-x-instruments.js" file can also be found inside the documentation's "javascript" folder, along with the "music-object.js" file.
In order to use this extension, the following JavaScript file(s) must first be sourced in...
- music-object.js (version 3.3.0 or higher)
For more information on using extensions, consult the section About Music Object Extensions.
| Name |
Short Description |
| Instance Methods |
| getProgramName |
Returns a string value, representing the name of the instrument that the specified MIDI channel is currently set to. |
| Static Methods |
| Music.getProgramName |
Returns a string value, representing the name of the instrument that corresponds to the specified bank number and program number. |
| Music.getPercussionName |
Returns a string value, representing the name of the percussion instrument that corresponds to the specified bank number and note number. |
| Static Properties |
| Music.programNames |
A two-dimensional array representing all the instruments in the Beatnik soundbank. |
|
|
The getProgramName method returns a string value, representing the name of the instrument that the specified MIDI channel is currently set to.
|
getProgramName ( ) |
|
ProgramNameSTR |

- this method is not able to return the name of an instrument in the User Bank (bank 2)
The Music.getProgramName static method returns a string value, representing the name of the instrument that corresponds to the specified bank number and program number.
|
ProgramNameSTR |

- this method is not able to return the name of an instrument in the User Bank (bank 2)
The Music.getPercussionName static method returns a string value, representing the name of the percussion instrument that corresponds to the specified bank number and note number.
|
PercussionNameSTR |

- this method is not able to return the name of a percussion instrument in the User Bank (bank 2)
The Music.programNames static property is a two-dimensional array representing all the instruments in the Beatnik soundbank.
The array contains two elements, each of which is an array representing the names of all the instruments in a specific bank. So, the element Music.programNames [0] is an array containing the names of all the instruments in the Beatnik GM Bank (General MIDI bank), and element Music.programNames [1] is an array containing the names of all the instruments in the Beatnik Special Bank. There is no element for the names of the instruments in the User Bank (bank 2), since the User Bank is not global like the GM Bank and Special Bank, but is unique to each different RMF file that contains custom instruments.
Now, to access a specific instrument name, one needs to access one of the elements of one of the bank arrays: Music.programNames [0] and Music.programNames [1]. For example, if one wished to find the instrument name of program number 10 in bank number 0, one would use the expression Music.programNames [0] [10]. One could achieve the same results by using the Music.getProgramName static method, as in the expression Music.getProgramName (0,10). In another example, if one wished to find the instrument name of program number 115 in bank number 1, one would use the expression Music.programNames [1] [115].
The primary difference between using the Music.programNames static property and the Music.getProgramName static method is speed. If one is writing an application which is going to iterate through all the instrument names in the Beatnik soundbank and offer them as options in a drop-down listbox, then using the static property will be far more efficient. Another benefit of using the static property is that one of the elements of the Music.programNames array could be passed as a parameter in a function call. A function that receives an array as a parameter could then iterate through the elements of the array and populate a listbox with instrument names or generate an HTML table of instrument names.
For example, the following source code listing shows a generic function that generates a listbox in an HTML page by receiving an array parameter that represents all the options of the listbox...
function generateListbox (listboxName,options) {
document.writeln ('<SELECT NAME="' + listboxName + '">');
for (var optionNo = 0; optionNo < options.length; optionNo++) {
document.writeln ('<OPTION VALUE="' + optionNo + '">' + options [optionNo]);
}
document.writeln ('</SELECT>');
}
generateListbox ('instrumentsGM',Music.programNames [0]);
|